home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / Ant Movie Catalog 3.5.0.2 / amc_install.exe / {app} / Scripts / KwCinema (IT).ifs < prev    next >
Text File  |  2005-02-04  |  10KB  |  339 lines

  1. (***************************************************
  2.  
  3. Ant Movie Catalog importation script
  4. www.antp.be/software/moviecatalog/
  5.  
  6. [Infos]
  7. Authors=Stefano Mora - stefano.mora@libero.it (2004)
  8. Title=KwCinema
  9. Description=Get movie info from KwCinema
  10. Site=http://www.kataweb.it/cinema
  11. Language=IT
  12. Version=1.0.3 - 02.02.2005
  13. Requires=3.5.0
  14. Comments=**Changes**|dinolib: adapted to v.3.5.0
  15. License=*  The source code of the script can be used in   |*  another program only if full credits to              |*  script author and a link to Ant Movie Catalog  |*  website are given in the About box or in       |*  the documentation of the program               |
  16. GetInfo=1
  17.  
  18. [Options]
  19.  
  20. ***************************************************)
  21.  
  22. program KwCinemaIt;
  23.  
  24. var
  25.  MovieName: string;
  26.  
  27. const
  28.   PATHLOG = 'c:\Programmi\Ant Movie Catalog\Log\LogKwCinema\';
  29.  
  30. function FindLine(Pattern: string; List: TStringList; StartAt: Integer): Integer;
  31. var
  32.   i: Integer;
  33. begin
  34.   result := -1;
  35.   if StartAt < 0 then
  36.     StartAt := 0;
  37.   for i := StartAt to List.Count-1 do
  38.     if Pos(Pattern, List.GetString(i)) <> 0 then
  39.     begin
  40.       result := i;
  41.       Break;
  42.     end;
  43. end;
  44.  
  45. // --------------------------------------------------
  46.  
  47. // Analizza la pagina e ricava i dati
  48. procedure LeggeFilm(Page: TStringList);
  49. var
  50.   strTmp, strTmp2, strTmp3: string;
  51.   LineNr: integer;
  52.   EndLine: integer;
  53.   BeginPos, EndPos: Integer;
  54.   bNome: boolean;
  55. begin
  56.  
  57. // Titoli
  58.   LineNr := FindLine('box-tit-film', Page, 0);
  59.   strTmp := Page.GetString(LineNr);
  60.   HTMLRemoveTags(strTmp);
  61.   // Titolo originale === titolo tradotto
  62.   SetField( fieldTranslatedTitle, strTmp);
  63.   SetField( fieldOriginalTitle, strTmp);
  64.  
  65. // Immagine - Locandina
  66.   LineNr := FindLine('<div class="box-grigio">', Page, LineNr);
  67.   if LineNr <> -1 then
  68.     begin
  69.     strTmp := Page.GetString(LineNr+1);
  70.     BeginPos := pos('assente.gif', strTmp); // Verifica che ci sia l'immagine
  71.     if BeginPos=0 then
  72.       begin
  73.         BeginPos := pos('src="', strTmp)+4;
  74.         delete( strTmp, 1, BeginPos);   // cancella per poter trovare l'altro '"'
  75.         BeginPos := pos('"', strTmp)-1;
  76.         strTmp := copy( strTmp, 1, BeginPos);
  77.         GetPicture(strTmp);  // Richiede l'immagine
  78.         end
  79.     end
  80.   
  81. // Cast
  82.   LineNr := FindLine('<div class="header-tit-int">Cast</div>', Page, LineNr);
  83.   if LineNr <> -1 then
  84.     begin
  85.     EndLine := FindLine('<div class="row"> </div>', Page, LineNr)-2;
  86.     strTmp :='';
  87.     while LineNr<EndLine do
  88.       begin
  89.       bNome := false;
  90.       // Controlla se deve aggiungere una virgola tra i nomi
  91.       if strTmp<>'' then strTmp := strTmp+', ';
  92.  
  93.       LineNr :=  LineNr+2;
  94.       strTmp2 := Page.GetString(LineNr);
  95.  
  96.       // Controlla se c'e' grassetto -> nome personaggio
  97.       BeginPos := pos('<b>', strTmp2)+3;
  98.       EndPos := pos('</b>', strTmp2);
  99.       if EndPos-BeginPos > 1 then
  100.         begin
  101.         strTmp3 := copy( strTmp2, BeginPos, EndPos-BeginPos);
  102.         strTmp := strTmp + strTmp3;
  103.         bNome := true;
  104.         end;
  105.       if bNome then strTmp := strTmp + ' (';
  106.       
  107.       // Estrae il nome
  108.       delete( strTmp2, 1, EndPos+3);
  109.       HTMLRemoveTags(strTmp2);
  110.       strTmp := strTmp + strTmp2;
  111.  
  112.       if bNome then strTmp := strTmp + ')';
  113.       end;
  114.     SetField( fieldActors, strTmp);
  115.     end;
  116.  
  117. // Descrizione
  118.   strTmp:='';
  119.   LineNr := FindLine('Trama', Page, LineNr)+2;
  120.   EndLine := FindLine('<div class="row"> </div>', Page, LineNr);
  121.   // Colleziona tutte le righe di descrizione
  122.   while LineNr<EndLine do
  123.   begin
  124.     strTmp2 := Page.GetString(LineNr);
  125.     // Potrebbe esserci l'immagine del Morandini
  126.     HTMLRemoveTags(strTmp2);
  127.     strTmp2 := StringReplace(strTmp2, #9, '');  // Toglie i tabs
  128.     strTmp2 := trim(strTmp2);
  129.     if strTmp2 <> '' then strTmp := strTmp + strTmp2 +  ' ';
  130.     LineNr := LineNr+1;
  131.   end;
  132.   HTMLRemoveTags(strTmp);
  133.   SetField( fieldDescription, strTmp);
  134.  
  135. // Anno
  136.   LineNr := FindLine('Anno', Page, LineNr);
  137.   strTmp := Page.GetString(LineNr);
  138.   BeginPos := Pos('</b>', strTmp)+4;
  139.   EndPos := Pos('</p>', strTmp);
  140.   strTmp := copy( strTmp, BeginPos, EndPos-BeginPos);
  141.   SetField( fieldYear, strTmp);
  142.  
  143. // Nazione
  144.   LineNr := FindLine('Nazione', Page, LineNr);
  145.   strTmp := Page.GetString(LineNr);
  146.   BeginPos := Pos('</b>', strTmp)+4;
  147.   EndPos := Pos('</p>', strTmp);
  148.   strTmp := copy( strTmp, BeginPos, EndPos-BeginPos);
  149.   SetField( fieldCountry, strTmp);
  150.  
  151. // Produzione
  152.   LineNr := FindLine('Produzione', Page, LineNr);
  153.   strTmp := Page.GetString(LineNr);
  154.   BeginPos := Pos('</b>', strTmp)+4;
  155.   EndPos := Pos('</sp>', strTmp);     // qui nella pagina c'e' un </SP> !!
  156.   strTmp := copy( strTmp, BeginPos, EndPos-BeginPos);
  157.   SetField( fieldProducer, strTmp);
  158.  
  159. // Durata
  160.   LineNr := FindLine('Durata', Page, LineNr);
  161.   strTmp := Page.GetString(LineNr);
  162.   BeginPos := Pos('</b>', strTmp)+4;
  163.   EndPos := Pos('''</p>', strTmp);
  164.   strTmp := copy( strTmp, BeginPos, EndPos-BeginPos);
  165.   //ShowMessage(strTmp);
  166.   SetField( fieldLength, strTmp);
  167.  
  168. // Genere
  169.   LineNr := FindLine('Genere', Page, LineNr);
  170.   strTmp := Page.GetString(LineNr);
  171.   BeginPos := Pos('</b>', strTmp)+4;
  172.   EndPos := Pos('</p>', strTmp);
  173.   strTmp := copy( strTmp, BeginPos, EndPos-BeginPos);
  174.   //ShowMessage(strTmp);
  175.   SetField( fieldCategory, trim(strTmp));
  176.  
  177. // Regia
  178.   LineNr := FindLine('Regia', Page, LineNr);
  179.   EndLine := FindLine('<div class="row"> </div>', Page, LineNr);
  180.   strTmp := Page.GetString(LineNr);
  181.   BeginPos := pos('ia:', strTmp)+2;
  182.   Delete(strTmp, 1, BeginPos);
  183.   //ShowMessage(strTmp);
  184.   LineNr := LineNr+1;
  185.   //while LineNr<EndLine do
  186.   //  begin
  187.   //  strTmp := strTmp + trim(Page.GetString(LineNr)) +  ' ';
  188.   //  LineNr := LineNr+1;
  189.   //  end;
  190.   HTMLRemoveTags(strTmp);
  191.   //ShowMessage(strTmp);
  192.   SetField( fieldDirector, trim(strTmp));
  193.  
  194. // Link
  195.   LineNr := FindLine('Link:', Page, LineNr);
  196.   if LineNr<>-1 then
  197.     begin
  198.     strTmp := Page.GetString(LineNr+1);
  199.     if (strTmp = '') then strTmp := Page.GetString(LineNr+2);
  200.     if (strTmp = '') then strTmp := Page.GetString(LineNr+3);
  201.     BeginPos := pos('href="', strTmp)+6;
  202.     EndPos := pos('" ', strTmp);
  203.     strTmp := copy( strTmp, BeginPos, EndPos-BeginPos);
  204.     SetField( fieldURL, strTmp);
  205.     end
  206.  
  207.   // Si sposta nella pagina dei risultati
  208.   //DisplayResults;
  209. end;
  210.  
  211. // ---
  212.  
  213. procedure AnalyzePage(Address: string);
  214.  
  215. var
  216.   Page: TStringList;
  217.   strPage, MovieAddr, MovieTitle : string;
  218.   BeginPos, EndPos: Integer;
  219.   
  220.   LineNr: Integer;
  221.   rigalista: string;
  222.   rigahtml: string;
  223.   strTmp: string;
  224.   altrapagina: string;
  225.  
  226. begin
  227.   // Crea la lista
  228.   Page:= TStringList.Create;
  229.   
  230.   // Riceve la pagina
  231.   Page.Text := GetPage(Address);
  232.   //Page.LoadFromFile(PATHLOG+'il colpo.res');
  233.  
  234.   BeginPos:= FindLine('Nessun film trovato', Page, 0);
  235.   if BeginPos <> -1 then
  236.     begin
  237.     ShowMessage('Film non trovato !');
  238.     exit;
  239.     end;
  240.  
  241.   // Controllare che ci siano film !!
  242.   BeginPos:= FindLine('<div class="header-tit-int">Hai cercato <i>', Page, 0);
  243.   if(BeginPos = -1) then
  244.     begin
  245.     // Trovato il film
  246.     LeggeFilm(Page);
  247.     end
  248.  
  249.   else  // Lista di film
  250.  
  251.     begin
  252.  
  253.     // Salva la pagina per debug
  254.     //Page.SaveToFile(PATHLOG+MovieName+'.res');
  255.  
  256.     PickTreeClear;
  257.     PickTreeAdd('Risultati ricerca per "' + MovieName + '":', '');
  258.  
  259.     LineNr := FindLine('<td><b><a href="', Page, BeginPos);
  260.     while LineNr <> -1 do
  261.       begin
  262.  
  263.       // Riga con indirizzo e titolo del film
  264.       rigahtml:= Page.GetString(LineNr);
  265.  
  266.       BeginPos:= pos('href="', rigahtml)+6;
  267.       EndPos:= pos('" >', rigahtml);
  268.       MovieAddr:= copy( rigahtml, BeginPos, EndPos-BeginPos);
  269.  
  270.       BeginPos:= EndPos+3;
  271.       EndPos:= pos('</a></b>', rigahtml);
  272.       MovieTitle:= copy( rigahtml, BeginPos, EndPos-BeginPos);
  273.  
  274.       // Legge l'anno
  275.       strTmp := Page.GetString(LineNr+1);
  276.       HTMLRemoveTags(strTmp);
  277.       MovieTitle := MovieTitle + ' [' + trim(strTmp) + '] ';
  278.  
  279.       // Legge il regista
  280.       strTmp := Page.GetString(LineNr+2);
  281.       HTMLRemoveTags(strTmp);
  282.       //ShowMessage(strTmp);
  283.       MovieTitle := MovieTitle + trim(strTmp);
  284.  
  285.       // Add to listbox
  286.       PickTreeAdd(MovieTitle, MovieAddr);
  287.  
  288.       // Restart the process
  289.       LineNr := LineNr+2;
  290.       LineNr := FindLine('<td><b><a href="', Page, LineNr);
  291.       end;
  292.  
  293.       // Controlla se ci sono altre pagine di risultati
  294.       LineNr := FindLine('>Avanti<', Page, LineNr);
  295.       if LineNr <> -1 then
  296.         begin
  297.         PickTreeAdd('Ci sono altre pagine risultato ...', '');
  298.         
  299.         // Estrae l'indirizzo per un'altra pagina
  300.         strTmp := Page.GetString(LineNr);
  301.         BeginPos := pos('href="', strTmp)+6;
  302.         EndPos := pos('" id=', strTmp);
  303.         altrapagina := copy( strTmp, BeginPos, EndPos-BeginPos);
  304.         //ShowMessage(altrapagina);
  305.         end;
  306.  
  307.       // Visualizza la lista e fa scegliere
  308.       if(PickTreeExec(Address)) then
  309.         begin
  310.         Address := 'http://www.kataweb.it'+Address;
  311.         Page.text := GetPage(Address);
  312.  
  313.         // Salva la pagina per debug
  314.             //Page.SaveToFile(PATHLOG+MovieName+'.film');
  315.  
  316.         LeggeFilm(Page);
  317.         end;
  318.     end;
  319.   Page.Free();
  320. end;
  321.  
  322. // -------------------- main
  323.  
  324. begin
  325.   if CheckVersion(3,5,0) then
  326.   begin
  327.     // Considera il titolo tradotto, se vuoto il titolo originale
  328.     MovieName := GetField(fieldTranslatedTitle);
  329.     if MovieName = '' then MovieName := GetField(fieldOriginalTitle);
  330.     // Chiede conferma del titolo
  331.     Input('KwCinema Import', 'Titolo del film:', MovieName);
  332.     if MovieName <> '' then
  333.     begin
  334.       AnalyzePage('http://www.kataweb.it/cinema/cerca.jsp?textfield='+ UrlEncode(MovieName) +'&select=film');
  335.     end;
  336.   end else
  337.     ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.5.0)');
  338. end.
  339.